<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Creates a new DatePeriod object</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.dateperiod.html">DatePeriod</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.datetime.html">Date/Time 函数</a></div>
 <div class="up"><a href="class.dateperiod.html">DatePeriod</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="dateperiod.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DatePeriod::__construct</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0)</p><p class="refpurpose"><span class="refname">DatePeriod::__construct</span> &mdash; <span class="dc-title">Creates a new DatePeriod object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-dateperiod.construct-description">
  <h3 class="title">说明</h3>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DatePeriod::__construct()</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$start</code></span>
   , <span class="methodparam"><span class="type"><a href="class.dateinterval.html" class="type DateInterval">DateInterval</a></span> <code class="parameter">$interval</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$recurrences</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code></span>
  ] )</div>

  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DatePeriod::__construct()</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$start</code></span>
   , <span class="methodparam"><span class="type"><a href="class.dateinterval.html" class="type DateInterval">DateInterval</a></span> <code class="parameter">$interval</code></span>
   , <span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$end</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code></span>
  ] )</div>

  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DatePeriod::__construct()</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$isostr</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Creates a new DatePeriod object.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-dateperiod.construct-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">start</code></em></dt>

     <dd>

      <p class="para">
       The start date of the period.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">interval</code></em></dt>

     <dd>

      <p class="para">
       The interval between recurrences within the period.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">recurrences</code></em></dt>

     <dd>

      <p class="para">
       The number of recurrences.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">end</code></em></dt>

     <dd>

      <p class="para">
       The end date of the period.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">isostr</code></em></dt>

     <dd>

      <p class="para">
       An ISO 8601 repeating interval specification.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">options</code></em></dt>

     <dd>

      <p class="para">
       Can be set to <strong><code>DatePeriod::EXCLUDE_START_DATE</code></strong> to
       exclude the start date from the set of recurring dates within the
       period.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-dateperiod.construct-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2224">
    <p><strong>Example #1 DatePeriod example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$start&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2012-07-01'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$interval&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">'P7D'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$end&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2012-07-31'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$recurrences&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$iso&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'R4/2012-07-01T00:00:00Z/P7D'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;All&nbsp;of&nbsp;these&nbsp;periods&nbsp;are&nbsp;equivalent.<br /></span><span style="color: #0000BB">$period&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DatePeriod</span><span style="color: #007700">(</span><span style="color: #0000BB">$start</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$interval</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$recurrences</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$period&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DatePeriod</span><span style="color: #007700">(</span><span style="color: #0000BB">$start</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$interval</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$end</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$period&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DatePeriod</span><span style="color: #007700">(</span><span style="color: #0000BB">$iso</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;By&nbsp;iterating&nbsp;over&nbsp;the&nbsp;DatePeriod&nbsp;object,&nbsp;all&nbsp;of&nbsp;the<br />//&nbsp;recurring&nbsp;dates&nbsp;within&nbsp;that&nbsp;period&nbsp;are&nbsp;printed.<br /></span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">$period&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
2012-07-01
2012-07-08
2012-07-15
2012-07-22
2012-07-29
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2225">
    <p><strong>Example #2 DatePeriod example with <strong><code>DatePeriod::EXCLUDE_START_DATE</code></strong></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$start&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2012-07-01'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$interval&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateInterval</span><span style="color: #007700">(</span><span style="color: #DD0000">'P7D'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$end&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">'2012-07-31'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$period&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DatePeriod</span><span style="color: #007700">(</span><span style="color: #0000BB">$start</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$interval</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$end</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">DatePeriod</span><span style="color: #007700">::</span><span style="color: #0000BB">EXCLUDE_START_DATE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;By&nbsp;iterating&nbsp;over&nbsp;the&nbsp;DatePeriod&nbsp;object,&nbsp;all&nbsp;of&nbsp;the<br />//&nbsp;recurring&nbsp;dates&nbsp;within&nbsp;that&nbsp;period&nbsp;are&nbsp;printed.<br />//&nbsp;Note&nbsp;that,&nbsp;in&nbsp;this&nbsp;case,&nbsp;2012-07-01&nbsp;is&nbsp;not&nbsp;printed.<br /></span><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">$period&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
2012-07-08
2012-07-15
2012-07-22
2012-07-29
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="class.dateperiod.html">DatePeriod</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.datetime.html">Date/Time 函数</a></div>
 <div class="up"><a href="class.dateperiod.html">DatePeriod</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
